import instance from "../util/request";

export async function updateBook(bookData) {
  try {
    const response = await instance.put("/book", bookData);
    return response.data;
  } catch (error) {
    console.error("修改图书出错:", error);
    throw error;
  }
}

export async function updateBookCover(bookId, coverData) {
  const formData = new FormData();
  formData.append("file", coverData);
  try {
    const response = await instance.post(`/book/${bookId}/cover`, formData, {
      headers: {
        "Content-Type": "multipart/form-data", // axios 会自动设置，通常可省略
      },
    });
    return response.data;
  } catch (error) {
    console.error("修改图书出错:", error);
    throw error;
  }
}
